import { FC, useState, useEffect } from 'react';
import useTimer from './useTimer';
import request from 'umi-request';

const Index: FC = () => {
  const time = useTimer();
  const [wtNm, set_wtNm] = useState<string>('');
  const [wtTemp, set_wtTemp] = useState<number>(0);

  useEffect(() => {
    request
      .get(
        'http://api.k780.com/?app=weather.realtime&weaId=94&ag=today&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json',
      )
      .then((res) => {
        // console.log(res.result);
        const { realTime } = res.result;
        set_wtNm(realTime.wtNm);
        set_wtTemp(realTime.wtTemp);
      });
  }, []);

  return (
    <>
      <div className="nav">
        <div className="nav-title">首页</div>
        <span>
          {wtNm} - {wtTemp} - {time}
        </span>
      </div>
    </>
  );
};

export default Index;
